package Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;

public class Test2 {
    //点名器
    //需求：在上一题的概率的基础上
    // 被点到将不会再次点到，除非下一轮
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        //创建集合，存储数字，代表概率
        ArrayList<Integer> list=new ArrayList<>();
        Collections.addAll(list,1,1,1,1,1,1,1,0,0,0);
        Random r=new Random();
//        int index=r.nextInt(list.size());
//        int num=list.get(index);
//        System.out.println(num);

        //创建两个集合，分别代表男和女
        ArrayList<String> boylist=new ArrayList<>();
        ArrayList<String> girllist=new ArrayList<>();
        Collections.addAll(boylist,"男6","男5","男4","男3","男2","男1");
        Collections.addAll(girllist,"女6","女5","女4","女3","女2","女1");
        //创建两个回收站，回收被点过名的
        ArrayList<String> reboylist=new ArrayList<>();
        ArrayList<String> regirllist=new ArrayList<>();

        while(true){
            int index=r.nextInt(list.size());
            int num=list.get(index);
            System.out.println(num);
            //判断数字，输出对应的男或女
            if(num==1){
                //判断集合在还有几个元素
                if(boylist.size()==0){
                    //如果为0，则表示需要进行下一轮，把回收站内的元素添加到原本集合中
                    boylist.addAll(reboylist);
                    //清空
                    reboylist.clear();
                }
                if(boylist.size()!=0){
                    int boynum=r.nextInt(boylist.size());
                    //根据索引删除返回对应的元素
                    String name= boylist.remove(boynum);
                    System.out.println(name);
                    //把名字添加到回收集合内并从原本集合中删除
                    Collections.addAll(reboylist,name);
                }

            }
            else{
                //判断集合在还有几个元素
                if(girllist.size()==0){
                    //如果为0，则表示需要进行下一轮，把回收站内的元素添加到原本集合中
                    girllist.addAll(regirllist);
                    //清空
                    regirllist.clear();
                }
                if(girllist.size()!=0){
                    int girlnum=r.nextInt(girllist.size());
                    //根据索引删除返回对应的元素
                    String name= girllist.remove(girlnum);
                    System.out.println(name);
                    //把名字添加到回收集合内
                    Collections.addAll(regirllist,name);
                }

            }
            System.out.println("按1继续，按0结束");
            int next = sc.nextInt();
            if(next==0){
                continue;
            }
            if(next==1){
                break;
            }
        }

    }
}
